// pages/combo/combo.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        historyLists: [],
        isLoading: true,
        showMore: true,
        theme:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var cacheUserInfo = wx.getStorageSync('user_phone');
        var that = this;
        // 每次页面打开的时候, 分页先置为1
        that.setData({
          page: 1
        });
    
        wx.request({
          url: app.globalData.domain + 'v2/index/getFeeOrder',
          method: 'post',
          data: {
            user_phone: cacheUserInfo.phoneNumber?cacheUserInfo.phoneNumber:'',
            page: that.data.page
          },
          success (res) {
            for (var i = 0; i < res.data.data.data.length; i++) {
              that.data.historyLists.push(res.data.data.data[i]);
            }
            that.setData({
              historyLists: that.data.historyLists,
              isLoading: false
            });
            console.log('个人订单历史', that.data.historyLists);
          }
        })
    },
    onShow(){
      if(wx.getStorageSync('theme') == 'style1'){
        this.setData({
          theme:'style1',
  
        })
    }else{
        this.setData({
          theme:'init',
        })
    }
    },
    /**
     * 加载更多
     */
    loadMore() {
        var that = this;
        var cacheUserInfo = wx.getStorageSync('user_phone');
        
        wx.request({
          url: app.globalData.domain + 'v2/index/getFeeOrder',
          method: 'post',
          data: {
            user_phone: cacheUserInfo.phoneNumber?cacheUserInfo.phoneNumber:'',
            page: that.data.page + 1
          },
          success (res) {
            for (var i = 0; i < res.data.data.data.length; i++) {
              that.data.historyLists.push(res.data.data.data[i]);
            }
            that.setData({
              historyLists: that.data.historyLists,
              page: that.data.page + 1,
              isLoading: false
            });

            // 如果当前页码 = 总页数. 隐藏加载更多
            if (that.data.page >= res.data.data.last_page) {
              that.setData({
                showMore: false
              });
            }
          }
        })
    }
})